package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.impl.NuseringProjectServiceImpl;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NuseringProjectController {
    @Autowired
    private NuseringProjectServiceImpl nuseringProjectService;

    /**
     * @Description: 分页条件查询护理项目
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/28 11:52
     */
    @GetMapping
    @ApiOperation("分页条件查询护理项目列表")
    public ResponseResult getByPage(@ApiParam(value = "护理项目名称")
                                    @RequestParam(value = "name", required = false) String name,
                                    @ApiParam(value = "状态：0-禁用，1-启用")
                                    @RequestParam(value = "status", required = false) Integer status,
                                    @ApiParam(value = "当前页码")
                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @ApiParam(value = "每页显示数量")
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        /*用vo实体类来返回给前端页面*/
        PageResponse<NursingProjectVo> pageResponse = nuseringProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

    /**
     * @Description: 新增护理项目
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/28 20:24
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    /*dto用来接前端参数*/
    public ResponseResult addNusPro(@ApiParam(value = "护理项目数据传输对象", required = true)
                                    @RequestBody NursingProjectDto nursingProjectDto) {
        nuseringProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * @Description: 根据id查询护理项目
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/29 14:57
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult selectNurProById(@ApiParam(value = "护理项目id", required = true)
                                           @PathVariable(value = "id") long id) {

        NursingProjectVo nursingProjectVo = nuseringProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * @Description: 编辑修改护理项目
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/29 15:11
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult updateNurPro(@ApiParam(value = "护理项目id")
                                       /*使用dto来接前端传回来的数据*/
                                       @RequestBody NursingProjectDto nursingProjectDto) {
        nuseringProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * @Description: 删除护理项目
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/30 19:37
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNurPro(@ApiParam(value = "护理项目id")
                                       @PathVariable("id") long id){
        nuseringProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    /**
     * @Description: 启用禁用按钮设置
     * @Param:
     * @return:
     * @author:fsq
     * @date: 2024/5/30 19:45
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改启用禁用按钮")
    public ResponseResult updateStatusById(@ApiParam(value = "更改护理项目启用禁用")
                                           @PathVariable("id") Integer id,
                                           @PathVariable("status") int status){
        nuseringProjectService.updateStatusById(id,status);
        return ResponseResult.success();
    }
}
